<template>
    <div class="common courseStaticDetail">
        <innerCommon 
            :location="location"
        >
            <template slot="left">
                <span>学员列表</span>
                <a-input-search class="inputStyle" placeholder="搜索"  v-model="searchValue" enter-button @search="onSearch" />
            </template>
            <template slot="right">
                <download 
                    :name="'导出'"
                    :api="'manage/course/exportCourseDataDetail'"
                    :fileName="'成绩表.xls'"
                    :formData="{'courseId':courseId,'keyword':searchInfo.keyword}"
                ></download>
                <a-button type="primary" style="margin-left:10px" @click="returnBack()">返回</a-button>
            </template>
            <div slot="table">
                <a-table 
                    size="middle"
                    :columns="columns" 
                    :data-source="list" 
                    :pagination="pagination"
                    :rowKey="record=>record.id"
                    @change="changePage"
                    :locale="{'emptyText': '暂无数据'}"
                    bordered>
                    <div slot="action" slot-scope="index,record" class="tableAction">
                        <span @click="toDetail(record.id)">查看详情</span>
                    </div>
                    <div slot="passed" slot-scope="index,record">
                        <span v-if="record.passed==2"></span>
                        <template v-else>
                            <span v-if="record.passed==0" style="color:red">否</span>
                            <span v-else style="color:green">是</span>
                        </template>
                    </div>
                </a-table>
            </div>
        </innerCommon>
    </div>
</template>
<script>
const columns=[
    {
        title: '序号',
        dataIndex: 'index',
        width:60
    },{
        title: '真实姓名',
        dataIndex: 'realname',
    },{
        title: '性别',
        dataIndex: 'gender',
    },{
        title: '用户名',
        dataIndex: 'name',
    },{
        title: '账号',
        dataIndex: 'account',
    },{
        title: '手机号',
        dataIndex: 'telephone',
    },{
        title: '身份证号',
        dataIndex: 'idCardNum',
    },{
        title: '所属单位',
        dataIndex: 'instituteName',
    },{
        title: '所属班级',
        dataIndex: 'class',
    },{
        title: '班级教师',
        dataIndex: 'teacher',
    },{
        title: '学习进度',
        dataIndex: 'taskProgress',
    },{
        title: '成绩',
        dataIndex: 'theoryScore',
    },{
        title: '是否合格',
        scopedSlots: { customRender: 'passed' },
    },{
        title: '考试时间',
        dataIndex: 'createTime',
    },{
        title: '证书编号',
        dataIndex: 'certificate',
    }
]
import download from "@/components/common/download"
import innerCommon from "@/components/common/innerCommon"
import {getCourseDataDetailApi} from "@/request/api"
export default {
    name:'courseStaticDetail',
    components:{innerCommon,download},
    watch:{
        searchValue:function(val){
            this.searchValue=val.trim()
        }
    },
    created(){
        this.courseId=this.$route.query.id
        this.location=[{
            name:"教学课堂管理",
            path:''
        },{
            name:"课程统计",
            path:'/courseStatic'
        },{
            name:this.$route.query.name,
            path:''
        }]
        this.init()
    },
    data(){
        return{
            columns,
            list:[],
            location:[],
            pagination:{pageSize:10,total:0,current:1},
            searchInfo:{
                page:1,
                pageSize:10,
                keyword:''
            },
            courseId:'',
            searchValue:''
        }
    },
    methods:{
        init(){
            this.getToken(getCourseDataDetailApi,{...this.searchInfo,'courseId':this.courseId},res=>{
                this.pagination.total=res.data.count
                this.list=res.data.rows.map((item,index)=>(({
                    ...item,
                    'index':(this.searchInfo.page-1)*10+index+1,
                    'certificate':item.paperRecord?(item.paperRecord.certificate?item.paperRecord.certificate.certNum:''):'',//证书编号
                    'theoryScore':item.paperRecord?item.paperRecord.theoryScore:'',//成绩
                    'passed':item.paperRecord?item.paperRecord.passed:2,//是否通过 0否1是2是不存在
                    'createTime':item.paperRecord?item.paperRecord.createTime:'',//考试时间
                })))
            })
        },
        returnBack(){
            this.$router.push({path:'/courseStatic',query:this.$route.query})
        },
        changePage(data){
            this.searchInfo.page=data.current
            this.pagination.current=data.current
            this.init()
        },
        onSearch(data){
            this.searchInfo.keyword=data.trim()
            this.init()
        },
    }
}
</script>